﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TweetMemeNET
{
    /// <summary>
    /// Represents a single TweetMeme story
    /// </summary>
    public class Story
    {
        /// <summary>
        /// Instantiates a new Story object based on an XML string
        /// </summary>
        /// <param name="xml"></param>
        public Story(string xml)
        {
            Populate(XElement.Parse(xml));
        }

        /// <summary>
        /// Instantiates a new Story object based on an XElement object
        /// </summary>
        /// <param name="tweetElement"></param>
        public Story(XElement tweetElement)
        {
            Populate(tweetElement);
        }

        protected void Populate(XElement e)
        {
            Title=e.Element(XName.Get("title", string.Empty)).Value;
            URL=e.Element(XName.Get("url", string.Empty)).Value;
            NumberOfRetweets=int.Parse(e.Element(XName.Get("url_count", string.Empty)).Value);
            NumberOfComments=int.Parse(e.Element(XName.Get("comment_count", string.Empty)).Value);
        }

        /// <summary>
        /// Gets the ID of the story
        /// </summary>
        public string Title { get; protected set; }

        /// <summary>
        /// Gets the URL of the story
        /// </summary>
        public string URL { get; protected set; }

        /// <summary>
        /// Gets the number of retweets
        /// </summary>
        public int NumberOfRetweets { get; protected set; }

        /// <summary>
        /// Gets the number of comments
        /// </summary>
        public int NumberOfComments { get; protected set; }
    }
}
